<template>
  <div class="creativeShowCourseDeatil">
    <div class="introduction" v-if="courseInfo">
      简介： {{ courseInfo.description || "无" }}
      <br />
      课程目标：{{ courseInfo.goal ? courseInfo.goal : "" }}
    </div>
    <div class="taskForce">
      <el-collapse v-model="activeNames">
        <el-badge
          v-for="(item, index) in courseInfo.content"
          :key="index"
          :is-dot="item.state === '未完全同步'"
          :max="10"
          class="item"
          :title="item.state === '未完全同步' ? '任务组内发生了变化' : ''"
        >
          <el-collapse-item
            ref="tasks"
            :id="'parentCollapse-' + index"
            :name="`${index}`"
            :class="{ isNoSync: item.state === '未完全同步' }"
          >
            <div class="retract" @click="retractTasks(index)" />
            <template slot="title">
              <div style="display: flex; align-items: flex-end">
                <div v-if="!unShowGroupIcon">
                  <img
                    :src="require('@/assets/images/taskUnfinish.png')"
                    class="tNfinishIcon"
                    v-if="item.state == taskState['unstudy']"
                  />
                  <img
                    :src="require('@/assets/images/taskLearning.png')"
                    class="tNfinishIcon"
                    v-if="item.state == taskState['studying']"
                  />
                  <img
                    :src="require('@/assets/images/taskFinish.png')"
                    class="tNfinishIcon"
                    v-if="item.state == taskState['studied']"
                  />
                </div>
                <div class="groupAndtaskIconPath">
                  <img :src=" item.iconPath" />
                </div>
                <div class="taskName">
                  {{ item.name }}
                </div>
                <div
                  class="mustInput"
                  v-if="item.name == '' && submissionCourseInfoStatus"
                  title="任务组名必填"
                >
                  *
                </div>
              </div>
              <div class="icondown2Box">
                <!-- <i class="iconfont iconzhcc_xiangxiajiantou-copy" /> -->
                <img
                  :src="require('@/assets/images/down.png')"
                  class="downIcon"
                />
              </div>
            </template>
            <div class="task-content">
              <template>
                <el-collapse v-model="activeNames">
                  <el-badge
                    v-for="(titem, tindex) in item.tasks"
                    :key="tindex"
                    :is-dot="
                      titem.state === '未发布' || titem.state === '已修改未发布'
                    "
                    :max="10"
                    :title="
                      titem.state === '未发布'
                        ? '任务未发布'
                        : titem.state === '已修改未发布'
                        ? '任务已修改未发布'
                        : titem.state
                    "
                  >
                    <el-collapse-item
                      :class="{
                        isFinishAndLearing:
                          titem.state && titem.state !== taskState['unstudy'],
                      }"
                      :name="`${index}-${tindex}`"
                    >
                      <template slot="title">
                        <div style="display: flex; align-items: flex-end">
                          <div
                            v-if="
                              titem.state == taskState['unstudy'] && !unShowGroupIcon
                            "
                          >
                            <img
                              :src="require('@/assets/images/lock.png')"
                              class="tNfinishIcon"
                            />
                          </div>
                          <div class="lockBox" v-if="!confirmPush">
                            <i
                              class="iconfont iconlock"
                              v-if="titem.isLockedForPublish === true"
                              title="不可发布"
                              @click.stop="titem.isLockedForPublish = false"
                            ></i>
                            <i
                              class="iconfont iconLOCKOPEN"
                              v-if="titem.isLockedForPublish === false"
                              title="可发布"
                              @click.stop="titem.isLockedForPublish = true"
                            ></i>
                          </div>
                          <div class="groupAndtaskIconPath">
                            <img
                              :src=" titem.iconPath"
                            />
                          </div>
                          <div class="taskName">
                            {{ titem.name }}
                          </div>
                          <div
                            class="mustInput"
                            v-if="
                              titem.name == '' && submissionCourseInfoStatus
                            "
                            title="任务名必填"
                          >
                            *
                          </div>
                          <div
                            class="timeRemaining"
                            v-if="titem.state == taskState['studying']"
                          >
                            <div
                              class="lastTime"
                              :style="{ width: `${'68%'}` }"
                            ></div>
                            <div class="time">剩余: 1小时58分钟</div>
                          </div>
                        </div>
                        <div class="taskController"></div>
                        <div
                          class="icondown2Box"
                          :class="{ btnUnShow: !titem.state }"
                        >
                          <!-- <i class="iconfont iconDownxiangxia28" /> -->
                          <img
                            :src="require('@/assets/images/down2.png')"
                            class="downIcon"
                          />
                        </div>
                      </template>
                      <div>
                        <div class="taskDesc">
                          简介：{{ titem.description || "无"}} <br />目标：{{
                            titem.goal
                          }}
                        </div>
                        <div>
                          <TaskType
                            v-for="(ditem, dindex) in titem.guidelines"
                            :taskIndex="
                              item.groupNoInCourse +
                              '-' +
                              titem.taskNoInGroup +
                              '-' +
                              ditem.noInTask
                            "
                            :ref="'taskType' + index + '-' + tindex"
                            :taskCommitJson="titem.taskCommitJson"
                            :courseInfo="courseInfo"
                            :courseData="courseData"
                            :titem="titem"
                            :item="ditem"
                            :key="dindex"
                            :submissionCourseInfoStatus="
                              submissionCourseInfoStatus
                            "
                            :unShowGroupIcon="unShowGroupIcon"
                          />
                        </div>
                      </div>
                    </el-collapse-item>
                  </el-badge>
                </el-collapse>
              </template>
            </div>
          </el-collapse-item>
        </el-badge>
      </el-collapse>
    </div>
  </div>
</template>

<script>
import { taskState } from "@/util/guidingtextType";
import TaskType from "@/views/courses/detail/task_N/taskType_N/taskType_N";
import { location } from "@/util/tool";

export default {
  components: { TaskType },
  data() {
    return {
      taskState,
      activeNames: [],
      loadingTasks: [],
      confirmFinishTask: false,
      currGroupitem: {}, // 当前点击的对象数据
      currTaskitem: {}, // 当前点击的对象数据
      location: location(window)
    };
  },
  props: {
    courseInfo: Object, // 父组件传入的数据
    courseData: Object,
    unShowGroupIcon: Boolean, // 在教师查看课程详情页面属于控制类参数
    learnGroupIndex: String, // 默认展开的的任务组或任务
    submissionCourseInfoStatus: Boolean, // 提交创作系统数据的状态
    confirmPush: Boolean, // 确认发布
  },
  watch: {
    learnGroupIndex(n, o) {
      // this.$nextTick(() => {
      if (n || n === "0") {
        this.activeNames.push(n.split("-")[0]);
        this.activeNames.push(n);
      }
      // })
    },
  },
  methods: {
    // 收起折叠组件
    retractTasks(index) {
      this.$refs.tasks[index].handleHeaderClick();
    },
  },
};
</script>

<style lang="stylus">
.creativeShowCourseDeatil {
  .introduction {
    padding: 21px 26px;
    // margin-top: 40px;
    position: relative;
    max-width: 835px;
    min-height: 130px;
    background-color: #ffffff;
    box-shadow: 0px 8px 16px 0px rgba(7, 23, 39, 0.1);
    border-radius: 18px;
    font-family: PMingLiU-ExtB;
    font-size: 14px;
    color: #000000;
  }

  .mustInput {
    cursor: pointer;
    position: absolute;
    left: -20px;
    font-family: Segoe UI;
    font-size: 16px;
    color: #f8060e;
    transform: translate(0, -50%);

    img {
      cursor: pointer;
      object-fit: cover;
      width: 12px !important;
      height: 12px !important;
    }
  }

  .taskForce {
    padding-top: 30px;
    max-width: 835px;

    .el-badge {
      width: 100%;

      .mustInput {
        left: 5px;
        transform: translate(0, 0%);
      }

      .el-badge__content {
        right: 8px;
        top: 4px;
      }
    }

    .el-collapse {
      border: 0;

      .el-collapse-item {
        position: relative;
        padding: 21px 0 15px;
        margin-bottom: 31px;
        background-color: #ffffff;
        box-shadow: 0px 8px 16px 0px rgba(7, 23, 39, 0.1);
        border-radius: 18px;
        transition: all 0.2s linear;

        .el-collapse-item__header, .el-collapse-item__wrap {
          border: 0;
        }

        .el-collapse-item__header {
          padding: 4px 31px 6px 26px;
          align-items: center;
          justify-content: space-between;
          height: auto;
          line-height: 1;
          font-size: 16px;
          font-weight: bold;
          color: #000000;
          transition: all 0.1s linear;

          img {
            vertical-align: bottom;
            margin-right: 8px;
            object-fit: cover;
            user-select: none;
            height: 22px;
          }

          .el-collapse-item__arrow {
            margin: 0;
          }

          .el-collapse-item__arrow .el-icon-arrow-right {
            display: none;
          }

          .el-icon-arrow-right:before {
            content: none;
          }

          .taskController {
            margin: 0 45px 0 auto;

            button {
              cursor: pointer;
              outline: none;
              width: 72px;
              height: 29px;
              border-radius: 5px;
              border: none;
              font-family: Yu Gothic UI;
              font-size: 14px;
              color: #ffffff;
            }

            .saveData {
              margin-right: 20px;
              background: #f6ad35;
            }

            .startLearning {
              background: #f6ad35;
            }

            .endLearn {
              background: #02497c;
            }

            .reLearning {
              background: #5ad551;
            }
          }

          .icondown2Box {
            margin: 0 0 0 auto;
            transition: transform 0.2s linear;

            .icondown2 {
              font-size: 22px;
              color: #8a8a8a;
            }

            .downIcon {
              margin: 0;
              object-fit: cover;
              height: 100%;
            }
          }

          .tNfinishIcon {
            // width: 19px;
            height: 22px;
          }

          .lockBox {
            margin-right: 10px;
          }

          .groupAndtaskIconPath {
            margin-right: 8px;
            width: 30px;
            height: 22px;

            img {
              z-index: 99;
              margin: 0;
              -o-object-fit: cover;
              object-fit: cover;
              width: 30px;
              height: 30px;
              border-radius: 50%;
              transform: translate(-5%, -10%);
            }
          }

          .taskName {
            font-family: PMingLiU-ExtB;
            font-size: 16px;
            color: #000000;
          }
        }

        .el-collapse-item__wrap {
          // background: #f9f9f9;
          .el-collapse-item__content {
            position: relative;
            padding-bottom: 52px;

            .retract {
              cursor: pointer;
              position: absolute;
              bottom: 0;
              width: 50px;
              height: 4px;
              left: calc(((100% - 50px) / 2));
              background: #bfbfbf;
            }

            .task-content {
              .el-collapse-item {
                // margin-top: 20px;
                // margin-bottom: 20px;
                // margin-top: 0;
                .el-collapse-item__header {
                  height: 32px;
                  position: relative;
                  padding-top: 0;
                  // padding-bottom: 17px;
                  padding-bottom: 0;

                  // .timeRemaining {
                  //   position: relative;
                  //   margin-left: 25px;
                  //   width: 100px;
                  //   height: 13px;
                  //   background-color: #eaeaea;
                  //   border-radius: 15px;
                  //   border: 1px solid #d2d6dc;

                  //   // overflow: hidden;
                  //   .lastTime {
                  //     height: 12px;
                  //     background: #5ad551;
                  //     border-radius: 15px;
                  //   }

                  //   .time {
                  //     position: absolute;
                  //     top: 0;
                  //     right: -105px;
                  //     font-weight: normal;
                  //     font-family: PMingLiU-ExtB;
                  //     font-size: 12px;
                  //     color: #000000;
                  //   }
                  // }

                  .taskName {
                    font-family: PMingLiU-ExtB;
                    font-size: 16px;
                    color: #000000;
                  }
                }

                .el-collapse-item__header::after {
                  position: absolute;
                  content: '';
                  left: 0;
                  top: 0;
                  width: 3px;
                  height: 25px;
                  background: #8a8a8a;
                  transform: translate(0, 15%);
                }

                .el-collapse-item__wrap {
                  .el-collapse-item__content {
                    padding: 4px 27px 40px;
                    background: #fff;

                    .taskDesc {
                      position: relative;

                      .mustInput, .chioceInput {
                        top: 50%;
                      }
                    }
                  }
                }
              }

              .el-collapse-item:first-child {
                // margin-top: 0;
              }

              .icondown2Box {
                transform: rotate(0);
              }

              .is-active {
                background: #fff;

                .el-collapse-item__wrap {
                  overflow: unset !important;
                }

                .el-collapse-item__header {
                  margin-bottom: 15px;

                  // padding-bottom: 17px;
                  .icondown2Box {
                    transform: rotate(180deg);
                  }
                }

                .el-collapse-item__content::after {
                  content: none;
                }
              }

              .isFinishAndLearing {
                .el-collapse-item__header::after {
                  background: #f6ad35;
                }
              }

              .el-collapse {
                .el-collapse-item {
                  .el-collapse-item__header {
                    .icondown2Box {
                      margin: 0;
                    }

                    .btnUnShow {
                      margin: 0 0 0 auto;
                    }
                  }
                }
              }
            }
          }
        }
      }

      .is-active {
        position: relative;
        background-color: #f9f9f9;

        .el-collapse-item__wrap {
          background: #f9f9f9;
          overflow: unset;
        }

        .el-collapse-item__header {
          padding-bottom: 24px;
        }

        .icondown2Box {
          transform: rotate(180deg);
        }
      }
    }
  }
}
</style>